{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " 1. Set of possible states : S  = {s0,s1,s2,......,sn} \n",
    " 2. Initial State: s0 \n",
    " 3. Transition Model: T(s,s')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let’s suppose we have a chain with only two states s0 and s1, where s0 is the initial state. The process is in s0 90% of the time and it can move to s1 the remaining 10% of the time. When the process is in state s1 it will remain there 50% of the time. Given this data we can create a Transition Matrix T as follows:\n",
    "T=[[0.90 0.10]\n",
    "   [0.50 0.50]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Computing the k-step transition probability:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "T: [[0.9 0.1]\n",
      " [0.5 0.5]]\n",
      "T_5: [[0.83504 0.16496]\n",
      " [0.8248  0.1752 ]]\n",
      "T_25: [[0.83333333 0.16666667]\n",
      " [0.83333333 0.16666667]]\n",
      "T_50: [[0.83333333 0.16666667]\n",
      " [0.83333333 0.16666667]]\n",
      "T_100: [[0.83333333 0.16666667]\n",
      " [0.83333333 0.16666667]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "#Here we declare the Transition Matrix T\n",
    "T = np.array([[0.90, 0.10],\n",
    "              [0.50, 0.50]])\n",
    "\n",
    "#Obtain T after 5 steps\n",
    "T_5 = np.linalg.matrix_power(T, 5)\n",
    "\n",
    "#Obtain T after 25 steps\n",
    "T_25 = np.linalg.matrix_power(T, 25)\n",
    "\n",
    "#Obtain T after 50 steps\n",
    "T_50 = np.linalg.matrix_power(T, 50)\n",
    "\n",
    "#Obtain T after 100 steps\n",
    "T_100 = np.linalg.matrix_power(T, 100)\n",
    "\n",
    "#Print the matrices\n",
    "print(\"T: \" + str(T))\n",
    "print(\"T_5: \" + str(T_5))\n",
    "print(\"T_25: \" + str(T_25))\n",
    "print(\"T_50: \" + str(T_50))\n",
    "print(\"T_100: \" + str(T_100))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
